import datetime, os, shutil, subprocess, re

REPOSITORY = "zeNewDesk"
ARCHIVE_DIRECTORY = 'zeDeskCommit'
FROM_REVISION = 2
TO_REVISION = 7

try:
	shutil.rmtree( ARCHIVE_DIRECTORY )
except OSError:
	pass
os.makedirs( ARCHIVE_DIRECTORY )

os.chdir( REPOSITORY )
vid = os.popen("hg grep -r %d:%d -l ."%(FROM_REVISION,TO_REVISION))

for line in vid.readlines():
	file = re.search('(\w|.)+(?=:)', line).group(0)
	dest = "../%s/%s" % (ARCHIVE_DIRECTORY,file)
	dir = re.search('(\w|.)+(?=/)', dest).group(0)
	try:
		os.makedirs( dir )
	except OSError:
		pass
	shutil.copy( file, dest )
  